<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="iscka" />
    <label for="toggle-all"></label>
    <!-- 1. 绑定键盘事件 -->
    <!-- 2. 数据绑定 -->
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keydown.enter="enterFn"
      v-model.trim="task"
    />
  </header>
</template>

<script>
// 新增任务
export default {
  name: "TodoHeader",
  props: ["arr"],
  data() {
    return {
      task: "",
    };
  },
  methods: {
    enterFn() {
      this.$emit("create", this.task);
      this.task = "";
    },
  },
  computed:{
    iscka:{
      set(checked){
        this.arr.forEach(obj=>obj.isDone = checked)
      },
      get(){
          return this.arr.length !== 0 && this.arr.every(obj => obj.isDone === true)
      }
    }
  }
};
</script>